<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-26 18:09
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class GetWxLikeBarberListCriteria extends BaseCriterias
{
	private $params;
	public function __construct($params)
	{
		$this->params = $params;
	}

	public function apply($model, RepositoryInterface $repository)
	{
		$select = 'hx_user.id,hx_user.nick as barberNick,hx_user_like.store_id as storeId,hx_picture.image as barberPortrait';
		$memberId = $this->params['member_id'];
		$res = $model->selectRaw($select)
			->leftJoin('user_like',function($join) use($memberId){
				return $join->on('user_like.user_id','user.id')
					->where('user_like.member_id','=',$memberId);
			})
			->leftJoin('picture','user.portrait','picture.id')
			->whereNotNull('user_like.store_id')
			->orderBy('id','asc');
		return $res;
	}
}